package com.hqyj.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Autor 伍军
 * @Date 2022/10/17 15:28
 * @Version 1.0
 **/
@RestController
@RequestMapping("/hello")
public class HelloController {

        //注入rabbimq的发送消息的对象实例
       @Autowired
        RabbitTemplate rabbitTemplate;

       //登录
      @GetMapping("/login")
      public String login(String name,String pwd){

          //---构建消息参数的数据类型----
          Map<String,Object> map =  new HashMap<>();
          map.put("userName",name);
          map.put("userPwd",pwd);
          //调用了银行转账业务

          //更新手机app最新的账号
          //发送短信通知

          //发送消息到mq服务中
          rabbitTemplate.convertAndSend("helloExchange","helloRoute01",map);

          return "success";

      }
    //convertSendAndReceive演示方法
    @GetMapping("/login01")
    public String login01(String name,String pwd){

        //---构建消息参数的数据类型----
        Map<String,Object> map =  new HashMap<>();
        map.put("userName",name);
        map.put("userPwd",pwd);

        //发送消息到mq服务中,获取消费者服务的返回值
        String info =rabbitTemplate.convertSendAndReceive("helloExchange","helloRoute02",map)+"";

        return info;

    }

    //扇形交换机发送消息
    @GetMapping("/login02")
    public String login02(String name,String pwd){

        //---构建消息参数的数据类型----
        Map<String,Object> map =  new HashMap<>();
        map.put("userName",name);
        map.put("userPwd",pwd);
        //发送消息到mq服务中
        rabbitTemplate.convertAndSend("createFanoutExchange","",map);

        return "success";

    }
    //主题交换机发送消息
    @GetMapping("/login03")
    public String login03(String name,String pwd){

        //---构建消息参数的数据类型----
        Map<String,Object> map =  new HashMap<>();
        map.put("userName",name);
        map.put("userPwd",pwd);
        //发送消息到mq服务中
        rabbitTemplate.convertAndSend("createTopicExange","topic.ddd",map);

        return "success";

    }


}
